package org.mypofolio.gui;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.TableColumnModel;

import org.mypofolio.model.CurrencyTableModel;

public class MainFrame extends JFrame{
	
	public MainFrame(){
		super("MyPofolio 1.0");
	}
	
	public void init(CurrencyTableModel model){
	    JTable tbl = new JTable(model);
	    tbl.setDefaultRenderer(java.lang.Number.class,
	        new FractionCellRenderer(10, 3, SwingConstants.RIGHT));

	    TableColumnModel tcm = tbl.getColumnModel();
	    tcm.getColumn(2).setPreferredWidth(650);
	    tcm.getColumn(2).setMinWidth(650);
	    TextWithIconCellRenderer renderer = new TextWithIconCellRenderer();
	    tcm.getColumn(0).setCellRenderer(renderer);
	    tcm.getColumn(2).setCellRenderer(new MyPofolioCellRenderer());


	    tbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	    tbl.setPreferredScrollableViewportSize(tbl.getPreferredSize());

	    JScrollPane sp = new JScrollPane(tbl);
	    getContentPane().add(sp, "Center");
	    pack();
	    addWindowListener(new WindowAdapter() {
	      public void windowClosing(WindowEvent evt) {
	        System.exit(0);
	      }
	    });
	    setVisible(true);	
	}

}
